//
//  ZXStatusPhotoView.m
//  ZXOCWeiBo
//
//  Created by mac on 15/12/11.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZXStatusPhotoView.h"

@interface ZXStatusPhotoView()

@property(nonatomic,weak)UIImageView* gifIcon;

@end

@implementation ZXStatusPhotoView


-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        
//        设置内容模式
        self.contentMode = UIViewContentModeScaleAspectFill;
//        超出部分剪切掉
        self.clipsToBounds = YES;
        
        //事先添加GIf图标
        UIImageView * gifIcon = [[UIImageView alloc]init];
        gifIcon.image = [UIImage imageNamed:@"timeline_image_gif"];
        [self addSubview:gifIcon];
        self.gifIcon = gifIcon;
    }
    return self;
}

-(void)setPhoto:(ZXPhoto *)photo
{
    _photo = photo;
//    使用SDwebImage显示图片
        [self sd_setImageWithURL:[NSURL URLWithString:photo.thumbnail_pic]];
    self.gifIcon.hidden = ![photo.thumbnail_pic hasSuffix:@".gif"];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
//    设置gifIcon的frm
    CGSize gifSize = self.gifIcon.image.size;
    CGFloat gifIconX = self.w - gifSize.width;
    CGFloat gifIconY = self.h - gifSize.height;
    self.gifIcon.frame = (CGRect){gifIconX,gifIconY,gifSize};
}
@end 
